import react from "react";
import React from "react";
import "../css/Inputbox.css";
import EventBus from "../EventBus";

class Inputbox extends React.Component{
  constructor(props){
    super();

    this.state = {
      placeholder:""
    }
  }

  componentWillMount(){
    this.setState({
      placeholder:this.props.placeholder
    })
  }

  render(){
    return(
      <div className="input_container">
        <div className="input_wrapper">
          <div>
            <input type="text" ref="input" placeholder={this.state.placeholder}/>
          </div>
          <div>
            <button onClick={()=>{
              //获取输入框内容
              let textValue = this.refs.input.value;
              if(textValue.length === 0){
                alert("清输入内容！");
                return;
              }

              let todo = {
                content:textValue,
                status:"pendding"
              }
              EventBus.emit("addTodo",todo)
            }}>点击添加</button>
            <button onClick={()=>{
              this.props.sendMessage("我是传递给父组件的数据")
            }}>点击向父组件传递数据</button>
          </div>
        </div>
      </div>
    )
  }
}

export default Inputbox;